Imports System.IO
Imports pixolut.BizBlox

Public Class Setup

    Public Shared Sub CreateDataSet()
        Console.WriteLine("Enter Setup.CreateDataSet() [please wait...]")
        Console.Out.Flush()
        Dim dObj As New DataAccess
        Dim foodUid(50) As Guid
        For i As Integer = 0 To foodUid.Length - 1
            foodUid(i) = Guid.NewGuid
            dObj.RunSQL("INSERT INTO [Food](FoodID, Name, Price)VALUES('" & foodUid(i).ToString() & "','" & ComposeFoodName(i) & "','" & CStr(CDbl(Rnd() * 6)) & "')")
        Next

        For i As Integer = 0 To 100
            Dim studentId As Guid = Guid.NewGuid()
            Dim studentName As String = ComposeStudentName(i)
            dObj.RunSQL("INSERT INTO [Student](StudentID, Name, Email, Age)VALUES('" & studentId.ToString() & "','" & studentName & "','" & ComposeStudentEmail(studentName) & "', '" & CStr(CInt((Rnd() * 10) + 10)) & "')")
            dObj.RunSQL("INSERT INTO [LunchOrder](LunchOrderID, StudentID, FoodID, dt_OrderDate, Quantity) VALUES('" & Guid.NewGuid().ToString() & "','" & studentId.ToString() & "', '" & foodUid(Rnd() * (foodUid.Length - 1)).ToString() & "', '" & Now.AddDays(Rnd() * 5).ToString("u") & "', '" & CStr(CInt(Rnd() * 4)) & "')")
        Next

        Console.WriteLine("Exit Setup.CreateDataSet()")
        Console.Out.Flush()
    End Sub

    Public Shared Sub ClearDataSet()
        Console.WriteLine("Enter Setup.ClearDataSet()")
        Dim dObj As New DataAccess
        dObj.RunSQL("DELETE FROM [Food]")
        dObj.RunSQL("DELETE FROM [Student]")
        dObj.RunSQL("DELETE FROM [LunchOrder]")
        Console.WriteLine("Exit Setup.ClearDataSet()")
    End Sub

    Private Shared Function ComposeFoodName(ByVal i As Integer) As String
        Dim foodSuffix() As String = {"pie", "roll", "souffle", "pasta", "sandwich"}
        Dim name As String = Dictionary.RandomEntry() & " " & foodSuffix((Rnd() * (foodSuffix.Length - 1)))
        Return name
    End Function

    Private Shared Function ComposeStudentName(ByVal i As Integer) As String
        Dim name As String = Dictionary.Entry(i) & " " & Dictionary.RandomEntry()
        Return name
    End Function

    Private Shared Function ComposeStudentEmail(ByVal name As String) As String
        Dim prefix As String = name.Replace(" ", "_")
        Dim webSuffix() As String = {"com", "edu", "gov", "mil", "org"}
        Dim mail As String = prefix & "@" & Dictionary.RandomEntry() & "." & webSuffix((Rnd() * (webSuffix.Length - 1)))
        Return mail
    End Function

End Class
